﻿using Game.Component;
using System;
using UnityEngine;




public class AreaInteraction : MonoBehaviour
{
    //public ConfigInteraction Config;

    public event Action OnInteractionTriggered;



    private void OnTriggerEnter(Collider other)
    {
        bool isGet = other.gameObject.TryGetComponent(out InteractionComponent output);
        if (!isGet) return;

        output.OnInteractionNoticed += OnNoticed;
        Debug.Log("执行订阅");
    }

    private void OnNoticed()
    {
        OnInteractionTriggered?.Invoke();
    }

    private void OnTriggerExit(Collider other)
    {
        bool isGet = other.gameObject.TryGetComponent(out InteractionComponent output);
        if (!isGet) return;

        Debug.Log("取消订阅");

        output.OnInteractionNoticed -= OnNoticed;
    }
}